//
//  ExpressDetailedCell.m
//  TengyunStation
//
//  Created by Johnny on 15/9/2.
//  Copyright (c) 2015年 xingrong. All rights reserved.
//

#import "ExpressDetailedCell.h"
#import "ExpressDetail.h"
#import "SocketMethod.h"
#import "TSHeader.h"

@implementation ExpressDetailedCell

- (void)awakeFromNib {
    // Initialization code
    self.layer.borderColor = LineColor.CGColor;
    self.layer.borderWidth = 0.5;
    for (int i = 1; i < 6; i ++) {
        UILabel *line = [[UILabel alloc] initWithFrame:CGRectMake(12, 40 * i, 308, 0.5)];
        if (i == 1) {
            line.frame = CGRectMake(0, 40, 320, 0.5);
            line.backgroundColor = OrangeColor;
        } else {
            line.backgroundColor = LineColor;
        }
        [self addSubview:line];
    }
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (void)reloadExpressDetailedCell:(ExpressDetail *)express {
    _express = express;
    _companyNameLabel.text = express.expressCompanyName;
    _expressIdLabel.text = [NSString stringWithFormat:@"%@",express.expressId];
    if (express.telephone.length > 0) {
        _phoneImageView.hidden = NO;
    } else {
        _phoneImageView.hidden = YES;
    }
    _telephoneLabel.text = express.telephone;
    if (express.address.length > 0) {
        _positionLabel.text = [NSString stringWithFormat:@"%@ / %@",express.position,express.address];
    } else {
        _positionLabel.text = express.position;
    }
    if (express.isOverdue == 0 || express.isOverdue == 1) {
        _expressTypeLabel.text = [SocketMethod expressType:express.expressType];
    } else if (express.isOverdue == 2) {
        _expressTypeLabel.text = [NSString stringWithFormat:@"%@(逾期%@天)",[SocketMethod expressType:express.expressType],express.remark];
    }
    _receiveTimeLabel.text = express.receiveTime;
    if ([_express.expressType isEqualToString:@"0029"]) {
        _timeLabel.text = @"退件时间";
    } else {
        _timeLabel.text = @"签收时间";
    }
    if (express.smsType == 0 || express.smsType == 1) {//发送中
        _smsImageView.image = [UIImage imageNamed:@"sms_wait"];
    } else if (express.smsType == 3) {//发送成功
        _smsImageView.image = [UIImage imageNamed:@"sms_success"];
    } else if (express.smsType == 2) {//发送失败
        _smsImageView.image = [UIImage imageNamed:@"sms_false"];
    }
    _retreatTimeLabel.text = express.retreatTime;
}

- (IBAction)callphone:(id)sender {
    if (_express.telephone.length > 0) {
        CustomAlertView *alert = [[CustomAlertView alloc] initWithTitle:_express.telephone message:nil delegate:self cancelButtonTitle:@"取消" sureButtonTitle:@"呼叫"];
        [alert show];
    }
}

#pragma mark CustomAlertView
- (void)customAlertView:(CustomAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
    if (buttonIndex == 1) {
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"tel://%@",_express.telephone]]];
    }
}

@end
